using UnityEngine;
using UnityEngine.UI;

public class RCCUIDashboardButton : MonoBehaviour
{
	public enum ButtonType
	{
		Start,
		ABS,
		ESP,
		TCS,
		Headlights
	}

	public ButtonType _buttonType;

	private RCCCarControllerV2[] cars;

	private void Start()
	{
		Check();
	}

	public void Act()
	{
		cars = UnityEngine.Object.FindObjectsOfType<RCCCarControllerV2>();
		switch (_buttonType)
		{
		case ButtonType.Start:
			for (int j = 0; j < cars.Length; j++)
			{
				if (cars[j].canControl)
				{
					cars[j].KillOrStartEngine();
				}
			}
			break;
		case ButtonType.ABS:
			for (int l = 0; l < cars.Length; l++)
			{
				if (cars[l].canControl)
				{
					cars[l].ABS = !cars[l].ABS;
				}
			}
			break;
		case ButtonType.ESP:
			for (int m = 0; m < cars.Length; m++)
			{
				if (cars[m].canControl)
				{
					cars[m].ESP = !cars[m].ESP;
				}
			}
			break;
		case ButtonType.TCS:
			for (int k = 0; k < cars.Length; k++)
			{
				if (cars[k].canControl)
				{
					cars[k].TCS = !cars[k].TCS;
				}
			}
			break;
		case ButtonType.Headlights:
			for (int i = 0; i < cars.Length; i++)
			{
				if (cars[i].canControl)
				{
					cars[i].headLightsOn = !cars[i].headLightsOn;
				}
			}
			break;
		}
		Check();
	}

	public void Check()
	{
		cars = UnityEngine.Object.FindObjectsOfType<RCCCarControllerV2>();
		switch (_buttonType)
		{
		case ButtonType.ABS:
			for (int l = 0; l < cars.Length; l++)
			{
				if (cars[l].canControl && cars[l].ABS)
				{
					GetComponent<Image>().color = new Color(1f, 1f, 1f, 1f);
				}
				else if (cars[l].canControl)
				{
					GetComponent<Image>().color = new Color(0.25f, 0.25f, 0.25f, 1f);
				}
			}
			break;
		case ButtonType.ESP:
			for (int j = 0; j < cars.Length; j++)
			{
				if (cars[j].canControl && cars[j].ESP)
				{
					GetComponent<Image>().color = new Color(1f, 1f, 1f, 1f);
				}
				else if (cars[j].canControl)
				{
					GetComponent<Image>().color = new Color(0.25f, 0.25f, 0.25f, 1f);
				}
			}
			break;
		case ButtonType.TCS:
			for (int k = 0; k < cars.Length; k++)
			{
				if (cars[k].canControl && cars[k].TCS)
				{
					GetComponent<Image>().color = new Color(1f, 1f, 1f, 1f);
				}
				else if (cars[k].canControl)
				{
					GetComponent<Image>().color = new Color(0.25f, 0.25f, 0.25f, 1f);
				}
			}
			break;
		case ButtonType.Headlights:
			for (int i = 0; i < cars.Length; i++)
			{
				if (cars[i].canControl && cars[i].headLightsOn)
				{
					GetComponent<Image>().color = new Color(1f, 1f, 1f, 1f);
				}
				else if (cars[i].canControl)
				{
					GetComponent<Image>().color = new Color(0.25f, 0.25f, 0.25f, 1f);
				}
			}
			break;
		}
	}
}
